package com.hs.device.all.service.impl;

import com.hs.common.core.constant.SecurityConstants;
import com.hs.common.core.domain.Result;
import com.hs.common.security.utils.SecurityUtils;
import com.hs.communication.common.entity.vo.DeviceVo;
import com.hs.communication.common.feign.RemoteChargerService;
import com.hs.device.all.entity.vo.DeviceListVo;
import com.hs.device.all.service.DeviceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class DeviceServiceImpl implements DeviceService {

    @Resource
    private RemoteChargerService remoteChargerService;

    @Override
    public DeviceListVo getStatistics() {

        long userId = SecurityUtils.getUserId();
        System.out.println("userId=" + userId);
        Result<DeviceVo> userResult = remoteChargerService.getStatistics(userId, SecurityConstants.INNER);
        List<DeviceVo> list = Stream.of(userResult)
                .filter(Objects::nonNull)
                .map(Result::getData)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        return DeviceListVo.builder().list(list).build();
    }

    @Override
    public List<List<String>> getSns() {
        long userId = SecurityUtils.getUserId();

        Result<List<String>> listResult = remoteChargerService.getSns(userId, SecurityConstants.INNER);
        List<List<String>> list = Stream.of(listResult)
                .filter(Objects::nonNull)
                .map(Result::getData)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        return list;
    }
}
